package TextFile
{
    import flash.filesystem.File;
    import flash.filesystem.FileMode;
    import flash.filesystem.FileStream;
    import flash.utils.ByteArray;

    public class TextFile extends File
    {
        private var _path:String;
        private var _text:String;
        
        public function TextFile(path:String) {
            _path = path;
            super(path);
        }
        
        public function get text():String {
            if(! _text) {
                load();
            }          
            return _text;  
        }
        
        private function load():void {
            var fs:FileStream = new FileStream();
            var ba:ByteArray = new ByteArray();
            var f:File = File(this);
            fs.open(File(this), FileMode.READ);
            fs.readBytes(ba, 0, fs.bytesAvailable);
            this._text = ba.toString();
            this._text = this._text.replace(/\r/g, "");
            fs.close();
        }
    }
}
    
